﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace XMLCreating.cs
{
    class BuildXML
    {
        class TeamStats
        {
           public  string name;
            public int goals;
           public int scored;
           public int passed;

            public TeamStats(string n, int g, int s, int p)
            {
                this.name = n;
                this.goals = g;
                this.scored = s;
                this.passed = p;
            }
        }
        static List<TeamStats> statistics = new List<TeamStats>()
        {
            new TeamStats("germany",25,30,7), 
            new TeamStats("italy", 40,45,5)
        };

        static void Build()
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlDeclaration declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            xmlDoc.AppendChild(declaration);
            
            XmlElement root = xmlDoc.CreateElement("teams");
            xmlDoc.AppendChild(root);

            foreach (TeamStats item in statistics)
            {
                XmlElement parent = xmlDoc.CreateElement("team");
                root.AppendChild(parent);
                parent.SetAttribute("name", item.name);

                XmlElement scoreNode = xmlDoc.CreateElement("score");
                XmlElement goalsScoredNode = xmlDoc.CreateElement("goals-active");
                XmlElement goalsPassedNode = xmlDoc.CreateElement("goals-passed");

                parent.AppendChild(scoreNode);
                parent.AppendChild(goalsScoredNode);
                parent.AppendChild(goalsPassedNode);

                XmlText scoreText = xmlDoc.CreateTextNode(""+item.goals);
                XmlText scoredGoalsText = xmlDoc.CreateTextNode(""+item.scored);
                XmlText passedGoalsText = xmlDoc.CreateTextNode("" + item.passed);

                scoreNode.AppendChild(scoreText);
                goalsScoredNode.AppendChild(scoredGoalsText);
                goalsPassedNode.AppendChild(passedGoalsText);

            }
            
            xmlDoc.Save("../../teams.xml");
        }

        static void Main(string[] args)
        {
            Build();
        }
    }
}
